package rxt.huiyi.com.rxterfit.presenter;

import rx.Subscriber;
import rxt.huiyi.com.rxterfit.Logger.Logger;
import rxt.huiyi.com.rxterfit.MainActivity;
import rxt.huiyi.com.rxterfit.entity.resultInfo.ContentSubscriberResultInfo;
import rxt.huiyi.com.rxterfit.view.IShowData;
import rxt.huiyi.com.rxterfit.view.impl.URL1Respository;

/**
 * Created by huiyi on 2017/4/24.
 */
public class Url1Presenter extends Presenter {

    private MainActivity activity;
    private IShowData review;

    public Url1Presenter(MainActivity activity, IShowData review) {
        super(activity);
        this.activity = activity;
        this.review = review;
    }

    public void loadURl1Data(URL1Respository respository) {

        rxJavaExecuter.execute(respository.getCategory(),
                catedataSubscriber = new CategoryDataSubscriber());
    }

    public void destroy() {
        if(catedataSubscriber != null)
            catedataSubscriber.unsubscribe();
    }

    private CategoryDataSubscriber catedataSubscriber;
    class CategoryDataSubscriber extends Subscriber<ContentSubscriberResultInfo> {

        @Override
        public void onCompleted() {
            Logger.i("交易结束");
        }

        @Override
        public void onError(Throwable e) {
            Logger.i("交易出错");
            review.showErrorData(e.getMessage());
        }

        @Override
        public void onNext(ContentSubscriberResultInfo contentSubscriberResultInfo) {
            review.showSuccessData(contentSubscriberResultInfo.toString());
        }

    }

}
